#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
#include<vector>
vector<int> sortArrayByParityII(vector<int>& nums)
{
    int right = 0;
    int left = 0;
    while (left < nums.size())
    {
        if (left % 2 == 0)
        {
            if (nums[left] % 2 != 0)
            {
                while (nums[right] % 2 != 0)
                {
                    right++;
                }
                swap(nums[left], nums[right]);
                left++;
            }
            else
                left++;

        }
        else
        {
            if (nums[left] % 2 != 1)
            {
                while (nums[right] % 2 != 1)
                {
                    right++;
                }
                swap(nums[left], nums[right]);
                left++;

            }
            else
                left++;
        }
    }
    return nums;

}
int main()
{
    vector<int> v;
    // [888,505,627,846]
  /*  v.push_back(888);
    v.push_back(505);
    v.push_back(627);
    v.push_back(846);*/
    //v.push_back(4);
    //v.push_back(2);
    //v.push_back(5);
    // 648,831,560,986,
    v.push_back(648);
    v.push_back(831);
    v.push_back(563);
    v.push_back(986);

    sortArrayByParityII(v);
    return 0;
}